[id].vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <template>
  2. <div>
  3. <!-- 页面头部 -->
  4. <TopicHead></TopicHead>
  5. <!-- 商圈详情 -->
  6. <div class="topicInfoBox">
  7. <div class="inner">
  8. <!-- 详情头部 -->
  9. <div class="infoHead">
  10. <div class="left">
  11. <div class="userInfo left">
  12. <el-badge value="楼主" class="item" type="warning">
  13. <img v-if='dataInfo.avatar' :src="dataInfo.avatar" alt="">
  14. <img v-else src='../../static/topic/Rectangle.png' alt="">
  15. </el-badge>
  16. <span>{{ dataInfo.nickname }}</span>
  17. </div>
  18. <div class="headContent left">
  19. <h2>{{ dataInfo.title }}</h2>
  20. <p v-show="dataInfo.group_name">
  21. 群聊:
  22. <span>{{ dataInfo.group_name }}</span>
  23. <button @click="joinGroup">加入群聊</button>
  24. </p>
  25. </div>
  26. </div>
  27. <div class="right">
  28. <div class="one" v-if="dataInfo.type == 1">科研</div>
  29. <div class="two" v-else-if="dataInfo.type == 2">维权</div>
  30. <div class="three" v-else-if="dataInfo.type == 3">讨论</div>
  31. <p>{{ dataInfo.updated_at }}</p>
  32. </div>
  33. </div>
  34. <!-- 详情页 文本+图片 -->
  35. <div class="infoContent" v-show="dataInfo.content">
  36. <div v-html="dataInfo.content"></div>
  37. </div>
  38. <div class="infoContent1" v-show="!dataInfo.content">
  39. <img src="../../static/topic/Document_empty.png" alt="">
  40. <span>可以看看大家的互动哦~</span>
  41. </div>
  42. <!-- 详情页评论 -->
  43. <div class="comment">
  44. <h3>评论</h3>
  45. <div class="commentList" v-for="item in replyList" v-show="page_total != 0">
  46. <div class="left">
  47. <img v-if='item.avatar' :src="item.avatar" alt="">
  48. <img v-else src='../../static/topic/Rectangle.png' alt="">
  49. <span class="name">{{ item.nickname }} : </span>
  50. <span class="context">{{ item.content }}</span>
  51. </div>
  52. <div class="right">
  53. <span class="time">{{ item.created_at }}</span>
  54. <!-- <span>回复</span> -->
  55. </div>
  56. </div>
  57. <div class="comment_empty" v-show="page_total == 0">
  58. <img src="../../static/topic/message_empty.png" alt="">
  59. <span>暂无评论</span>
  60. </div>
  61. </div>
  62. <!-- 分页 -->
  63. <div class="paginationBox" v-show="page_total != 0">
  64. <el-pagination background layout="prev, pager, next" :total="page_total" prev-text="上一页"
  65. next-text="下一页" :default-page-size="pageSize" @change="changePage" />
  66. </div>
  67. </div>
  68. </div>
  69. <div class="message">
  70. <div class="inner">
  71. <input v-model="content" placeholder="快来回复吧~" type="text" class="messageInput">
  72. <button class="btn" @click="addReply">确定</button>
  73. </div>
  74. </div>
  75. <!-- 页面底部 -->
  76. <!-- <HomeFoot></HomeFoot> -->
  77. <AdvertisingFoot></AdvertisingFoot>
  78. </div>
  79. </template>
  80. <script setup>
  81. //1.引用模块 start ---------------------------------------->
  82. //使用ref和reactive动态变量
  83. import { ref, reactive, onMounted } from 'vue'
  84. import { useRoute } from 'vue-router';
  85. //使用官方ssr请求模块
  86. import { useNuxtApp, useFetch } from '#app'
  87. //使用element-plus组件
  88. import { ElPagination, ElBadge, ElInput, ElMessage, ElMessageBox } from 'element-plus';
  89. // axios请求
  90. const nuxtApp = useNuxtApp();
  91. const axios = nuxtApp.$axios;
  92. //1.引用模块 end ---------------------------------------->
  93. //2.页面数据 start ---------------------------------------->
  94. const dataInfo = ref({})
  95. const groupId = useState("groupId", () => '')
  96. const replyList = useState("replyList", () => []) //评论列表
  97. //分页
  98. const page = ref(1)
  99. const pageSize = ref(5)
  100. let page_total = ref(0)
  101. const content = ref('')
  102. //2.页面数据 end ---------------------------------------->
  103. //3.获取商圈详情 start ---------------------------------------->
  104. const route = useRoute();
  105. const id = route.params.id; // 获取传递的 id 参数
  106. //页码发生改变
  107. const changePage = (val) => {
  108. console.log(val);
  109. page.value = val
  110. getTopicReply()
  111. }
  112. // 商圈信息
  113. const getTopicInfo = () => {
  114. let data = new FormData()
  115. data.append('id', id)
  116. axios.post('chat/getTopicInfo', data).then(res => {
  117. console.log('商圈信息', res);
  118. dataInfo.value = res.data
  119. groupId.value = res.data.group_id
  120. console.log(groupId.value);
  121. })
  122. }
  123. // 回复商圈 列表
  124. const getTopicReply = () => {
  125. let data = new FormData()
  126. data.append('id', id)
  127. data.append('page', page.value)
  128. data.append('page_size', pageSize.value)
  129. axios.post('chat/getTopicReply', data).then(res => {
  130. console.log('回复商圈列表 ', res);
  131. // replyList.value = res.data.data
  132. // page_total.value = res.data.total
  133. replyList.value = res.data.data.sort((a, b) => {
  134. return new Date(b.created_at) - new Date(a.created_at);
  135. });
  136. page_total.value = res.data.total
  137. console.log("replyList",replyList);
  138. })
  139. }
  140. onMounted(() => {
  141. getTopicInfo(); //商圈信息
  142. getTopicReply(); //回复商圈列表
  143. })
  144. //加入群聊
  145. const joinGroup = () => {
  146. ElMessageBox.confirm(
  147. '加入群聊后,页面跳转至后台群聊页面',
  148. '是否加入群聊?',
  149. {
  150. confirmButtonText: '是',
  151. cancelButtonText: '否',
  152. center: true,
  153. }
  154. ).then(() => {
  155. console.log('groupId.value', groupId.value);
  156. let data = new FormData()
  157. data.append('group_id', groupId.value)
  158. axios.post('chat/joinGroup', data).then(res => {
  159. console.log('加入群聊 ', res);
  160. if (res.code == 0 && res.message !== '已加入群') {
  161. ElMessage.error(res.message)
  162. } else if (res.code == 0 && res.message == '已加入群') {
  163. ElMessage({
  164. message: res.message,
  165. type: 'success',
  166. })
  167. setTimeout(() => {
  168. // window.location.href = ("http://adminpre.bjzxtw.org.cn/#/hall")
  169. window.open('http://adminpre.bjzxtw.org.cn/#/hall', '_blank');
  170. }, 1000)
  171. } else if (res.code == 200) {
  172. ElMessage({
  173. message: '加入成功',
  174. type: 'success',
  175. })
  176. setTimeout(() => {
  177. // window.location.href = ("http://adminpre.bjzxtw.org.cn/#/hall")
  178. window.open('http://adminpre.bjzxtw.org.cn/#/hall', '_blank');
  179. }, 1000)
  180. }
  181. })
  182. }).catch(() => {
  183. ElMessage({
  184. type: 'error',
  185. message: '已取消',
  186. })
  187. })
  188. }
  189. // 回复商圈
  190. const addReply = () => {
  191. let data = new FormData()
  192. data.append('id', id)
  193. data.append('content', content.value)
  194. axios.post('chat/addReply', data).then(res => {
  195. console.log('回复商圈 ', res);
  196. if (res.code == 0) {
  197. ElMessage.error(res.message)
  198. getTopicReply();
  199. } else if (res.code == 200) {
  200. ElMessage({
  201. message: '回复成功',
  202. type: 'success',
  203. })
  204. content.value = ''
  205. getTopicReply();
  206. }
  207. })
  208. }
  209. //3.获取商圈详情 end ---------------------------------------->
  210. </script>
  211. <style lang="less" scoped>
  212. .topicInfoBox {
  213. .inner {
  214. width: 1200px;
  215. margin: 0 auto;
  216. //信息头部
  217. .infoHead {
  218. height: 200px;
  219. padding: 65px 0 60px 40px;
  220. border-bottom: 1px solid rgba(0, 0, 0, 0.10);
  221. box-sizing: border-box;
  222. >.left {
  223. .userInfo {
  224. margin-right: 90px;
  225. .item {
  226. margin-top: -5px;
  227. margin-right: -5px;
  228. :deep(.el-badge__content.is-fixed) {
  229. position: absolute;
  230. right: calc(1px + var(--el-badge-size) / 2);
  231. top: 0;
  232. transform: translateY(-31%) translateX(79%);
  233. z-index: var(--el-index-normal);
  234. }
  235. img {
  236. width: 66px;
  237. height: 66px;
  238. vertical-align: middle;
  239. border-radius: 50%;
  240. }
  241. }
  242. span {
  243. margin-left: 15px;
  244. font-family: Microsoft YaHei, Microsoft YaHei;
  245. font-weight: 400;
  246. font-size: 18px;
  247. color: #333333;
  248. }
  249. }
  250. .headContent {
  251. h2 {
  252. font-family: Microsoft YaHei, Microsoft YaHei;
  253. font-weight: bold;
  254. font-size: 20px;
  255. color: #333333;
  256. margin-bottom: 26px;
  257. }
  258. >p {
  259. font-family: Microsoft YaHei, Microsoft YaHei;
  260. font-weight: 400;
  261. font-size: 16px;
  262. color: #333333;
  263. button {
  264. width: 86px;
  265. height: 32px;
  266. background-color: #028e21;
  267. color: #fff;
  268. border: none;
  269. margin-left: 100px;
  270. }
  271. }
  272. }
  273. }
  274. >.right {
  275. position: relative;
  276. div {
  277. position: absolute;
  278. right: 0;
  279. top: 0;
  280. width: 71px;
  281. height: 32px;
  282. line-height: 32px;
  283. text-align: center;
  284. background-color: #d9f0d6;
  285. margin-bottom: 29px;
  286. font-family: Microsoft YaHei, Microsoft YaHei;
  287. font-weight: 400;
  288. font-size: 16px;
  289. color: #33B023;
  290. }
  291. .one {
  292. color: #FFAA33;
  293. background-color: #fbebd5;
  294. }
  295. .two {
  296. color: #33B023;
  297. background-color: #d5ecd2;
  298. }
  299. .three {
  300. color: #666;
  301. background-color: #ebebeb;
  302. }
  303. p {
  304. width: 150px;
  305. text-align: right;
  306. position: absolute;
  307. top: 62px;
  308. right: 0;
  309. }
  310. }
  311. }
  312. // 有详情信息
  313. .infoContent {
  314. overflow: hidden;
  315. padding: 40px 46px;
  316. font-family: Microsoft YaHei, Microsoft YaHei;
  317. font-size: 20px;
  318. line-height: 40px;
  319. }
  320. //没有详情信息
  321. .comment_empty,
  322. .infoContent1 {
  323. height: 300px;
  324. line-height: 260px;
  325. text-align: center;
  326. img {
  327. width: 78px;
  328. height: 78px;
  329. vertical-align: -25px;
  330. vertical-align: middle;
  331. margin-right: 20px;
  332. }
  333. span {
  334. font-family: Microsoft YaHei, Microsoft YaHei;
  335. font-weight: bold;
  336. font-size: 26px;
  337. color: #CCCCCC;
  338. }
  339. }
  340. //评论
  341. .comment {
  342. h3 {
  343. height: 100px;
  344. padding-top: 30px;
  345. box-sizing: border-box;
  346. border-bottom: 1px solid #E1E1E1;
  347. font-family: Microsoft YaHei, Microsoft YaHei;
  348. font-weight: 400;
  349. font-size: 22px;
  350. color: #000000;
  351. }
  352. .commentList {
  353. height: 112px;
  354. border: 1px solid #E1E1E1;
  355. background-color: #fafafa;
  356. margin-top: 20px;
  357. padding: 30px 30px;
  358. box-sizing: border-box;
  359. .left {
  360. img {
  361. width: 52px;
  362. height: 52px;
  363. border-radius: 50%;
  364. vertical-align: middle;
  365. margin-right: 15px;
  366. }
  367. .name {
  368. font-family: Microsoft YaHei, Microsoft YaHei;
  369. font-weight: 400;
  370. font-size: 16px;
  371. color: #333333;
  372. margin-right: 30px;
  373. }
  374. .context {
  375. font-family: Microsoft YaHei, Microsoft YaHei;
  376. font-weight: bold;
  377. font-size: 16px;
  378. color: #333333;
  379. }
  380. }
  381. .right {
  382. padding: 14px 0;
  383. .time {
  384. font-family: Microsoft YaHei, Microsoft YaHei;
  385. font-weight: 400;
  386. font-size: 16px;
  387. color: #999999;
  388. margin-right: 30px;
  389. }
  390. span {
  391. font-family: Microsoft YaHei, Microsoft YaHei;
  392. font-weight: 400;
  393. font-size: 16px;
  394. color: #333333;
  395. }
  396. }
  397. }
  398. // .comment_empty {
  399. // height: 200px;
  400. // line-height: 200px;
  401. // text-align: center;
  402. // img {
  403. // width: 78px;
  404. // height: 78px;
  405. // vertical-align: -25px;
  406. // margin-right: 20px;
  407. // }
  408. // span {
  409. // font-family: Microsoft YaHei, Microsoft YaHei;
  410. // font-weight: bold;
  411. // font-size: 26px;
  412. // color: #CCCCCC;
  413. // }
  414. // }
  415. }
  416. }
  417. }
  418. //评论回复
  419. .message {
  420. width: 100%;
  421. height: 145px;
  422. line-height: 145px;
  423. background-color: #ecf5ee;
  424. .inner {
  425. .messageInput {
  426. width: 1049px;
  427. height: 67px;
  428. outline: none;
  429. border: 1px solid #E1E1E1;
  430. background-color: #fafafa;
  431. font-family: Microsoft YaHei, Microsoft YaHei;
  432. font-weight: 400;
  433. font-size: 18px;
  434. color: #666;
  435. padding-left: 20px;
  436. box-sizing: border-box;
  437. }
  438. .btn {
  439. width: 115px;
  440. height: 40px;
  441. border: none;
  442. background-color: #028e21;
  443. color: #fff;
  444. border-radius: 6px;
  445. margin-left: 36px;
  446. font-family: Microsoft YaHei, Microsoft YaHei;
  447. font-weight: 400;
  448. font-size: 16px;
  449. }
  450. }
  451. }
  452. //分页
  453. .paginationBox {
  454. display: flex;
  455. justify-content: center;
  456. margin-top: 60px;
  457. margin-bottom: 90px;
  458. // 鼠标移入后字体颜色
  459. :deep(.el-pagination:hover) {
  460. color: #139609;
  461. }
  462. :deep(.el-pagination.is-background .btn-next),
  463. :deep(.el-pagination.is-background .btn-prev) {
  464. width: 70px;
  465. height: 34px;
  466. margin: 0px 10px;
  467. border-radius: 4px;
  468. }
  469. :deep(.el-pagination.is-background .el-pager li) {
  470. margin: 0px 10px;
  471. width: 38px;
  472. height: 34px;
  473. border-radius: 4px;
  474. }
  475. :deep(.el-pagination.is-background .btn-next.is-active),
  476. :deep(.el-pagination.is-background .btn-prev.is-active),
  477. :deep(.el-pagination.is-background .el-pager li.is-active) {
  478. background-color: #028e21;
  479. color: #fff;
  480. }
  481. }
  482. </style>